package com.cbl.v.ssczs.mode.net;

import android.util.Log;

import com.cbl.v.ssczs.mode.baseapi.DataApi;
import com.cbl.v.ssczs.mode.entity.DataBean;
import com.cbl.v.ssczs.mode.entity.ItemBean;
import com.cbl.v.ssczs.mode.util.Tools;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王凡 on 2017/8/21.
 */

public class HttpRequestForResponse extends Response {


    /**
     * 获取数据
     * @param
     * @param callBack
     * @param order
     */
    public static void getData(final DataCallBack callBack, final int order){
        DataApi.getData( new HttpResponseHandler() {
            @Override
            public void onSuccess(NetMessage message) {
                Log.i("TTT","返回数据："+message.getJson());
                switch (message.getCode()){
                    case -1:
                        Tools.ShowInfo(context,"appId错误");
                        break;
                    case 400:
                        Tools.ShowInfo(context,"appId不存在");
                        break;
                    case 200:
                        DataBean dataBean=new Gson().fromJson(message.getData(),DataBean.class);
                        switch (dataBean.getIswap()){
                            case "1":
                                callBack.dataBack(dataBean.getWapurl(),order);
                                break;
                            case "0":
                                callBack.dataBack("",order);
                                break;
                        }
                        switch (dataBean.getIsmust()){
                            case "1":
                                callBack.upDateApp(dataBean.getUpurl());
                                break;
                            case "0"://不强制更新
                                callBack.upDateApp("");
                                break;
                        }

                        break;
                }
            }

            @Override
            public void onError(Throwable throwable) {
                Log.i("TTT","失败"+throwable.getMessage());
            }

            @Override
            public void onFinish() {
                //DialogUtils.disMissDialog();
                callBack.finishBack();
            }
        });
    }

    /**
     * 获取彩票信息
     * @param url
     * @param callBack
     * @param order
     */
    public static void getBallData(String url, final DataCallBack callBack, final int order){
        DataApi.getBallData(url, new HttpResponseHandler() {
            @Override
            public void onSuccess(NetMessage message) {
                Log.i("彩票","数据返回"+message.getJson());
                List<ItemBean> list=new Gson().fromJson(message.getData(),new TypeToken<ArrayList<ItemBean>>() {}.getType());
                callBack.dataBack(list,order);
            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onFinish() {
                callBack.finishBack();
            }
        });
    }




}
